//
//  XFMainTabViewController.m
//  SinaBlog_OC
//
//  Created by macs on 15/11/10.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

#import "XFMainTabViewController.h"
#import "XFHomeTableViewController.h"
#import "XFDiscoverTableViewController.h"
#import "XFMessageTableViewController.h"
#import "XFProfileTableViewController.h"
#import "XFMainTabBar.h"

#import "XFBaseNavController.h"
#import "XFComposeViewController.h"

@interface XFMainTabViewController ()

@end

@implementation XFMainTabViewController

- (void)compBtnDidClick {
  //进入发布微博界面
  UINavigationController *nav = [[UINavigationController alloc]
      initWithRootViewController:[[XFComposeViewController alloc] init]];

  [self presentViewController:nav animated:YES completion:nil];
}

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.

  XFMainTabBar *mainTabBar = [[XFMainTabBar alloc] init];

  [self setValue:mainTabBar forKey:@"tabBar"];

  [mainTabBar.compBtn addTarget:self
                         action:@selector(compBtnDidClick)
               forControlEvents:UIControlEventTouchUpInside];

  [self addsubViewController];
}

- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}

- (void)addsubViewController {

  [self addChildViewControllerWithVc:[[XFHomeTableViewController alloc] init]
                            andTitle:@"首页"
                        andImageName:@"tabbar_home"];
  [self addChildViewControllerWithVc:[[XFMessageTableViewController alloc] init]
                            andTitle:@"消息"
                        andImageName:@"tabbar_message_center"];
  [self
      addChildViewControllerWithVc:[[XFDiscoverTableViewController alloc] init]
                          andTitle:@"发现"
                      andImageName:@"tabbar_discover"];
  [self addChildViewControllerWithVc:[[XFProfileTableViewController alloc] init]
                            andTitle:@"我"
                        andImageName:@"tabbar_profile"];
}

- (void)addChildViewControllerWithVc:(UIViewController *)vc
                            andTitle:(NSString *)title
                        andImageName:(NSString *)imageName {

  XFBaseNavController *nav =
      [[XFBaseNavController alloc] initWithRootViewController:vc];
  vc.title = title;
  //  UIImage *lightImage =
  //      [[UIImage imageNamed:[imageName
  //      stringByAppendingString:@"_highlighted"]]
  //          imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  //  vc.tabBarItem.selectedImage = lightImage;
  //  [vc.tabBarItem setTitleTextAttributes:@{
  //    NSForegroundColorAttributeName : [UIColor orangeColor]
  //  } forState:UIControlStateSelected];
  [self.tabBar setTintColor:[UIColor orangeColor]];
  vc.tabBarItem.image = [UIImage imageNamed:imageName];
  [self addChildViewController:nav];
}

@end
